Code for scheduling