optimise the code