Clean up

Added some comments, checked for errors and cleaned up code a little bit