Fixed and simplified a few things in the "computeEnergy" function.