computeEnergies works correctly on the kernel

computeEnergies works correctly on the kernel.
Also sequential energies has been modified to check for out of bounds
references.