Cleaned up code and improved readability