rethought main program structure