Optimising code for performance