add comments; minor code cleanup