Improving the code