added comments and improved organization