Structure the main function