finished main routine, needs to be tested