Refactor main