added comments and some cleanup