Improving the code a bit