Optimising the code