Cleaned up some code

Made the code look tidier, added more comments for clarification