Code cleanup

Added some comments and cleaned some code up.