full C-like version added and corrected energies bug