Optimizing the code further