added comments and organized code