refactor & add comments