Improved the code