Clean up code and move methods to the appropriate class