beginning of scheduling code