Refactor, add comments.