Finished everything except for the free energy minimisation