Moved getEnergyLoss() into a function