Slight simplification in main function