Cleaned up the code a lot