Improved the code a bit