Improved the code a little