Code for resource scheduler