Split the main function