Added free energy minimsation function