Fixed few bugs in scheduler