code formatting and optimisation