slight simplification of main function