final refactor main