Cleaned up the code and made it pass formatting tests