added comments, code cleanup