refactor main & add comments