Optimizing the code