Functions and optimisation but not finish yet