Cleaned up parts of the code a bit