code cleanup, add comments, updates