Optimised the code