refactor Main