added comments, minor code cleanup