JS clean up and optimisation