fixed the free energy function