optimizing the code