split out some functions

to make main smaller