correct the free energy function