Removed some printouts, added comments and clarified code