An Improved Nonlocal History-Dependent Model for Gain and Noise in Avalanche Photodiodes Based on Energy Balance Equation