moved code into a method and out of main