Heavily improved the scheduler API