Cleaned up code and made it more readable