refactor out of main