add comments, refactor