Optimizing the code a bit