broke up main function into sub routines