organized code and added comments