refactor main