moved more logic out of main method