refactor to have schedule and assign functions.