extract the scheduler code into its own file