Refactor; add comments