Cleaned up code and made more readable