split main, add comments