add comments, code cleanup