Top-down main function implementation