Refactor main.