Added additional comments and cleaned up code