Main routine outline