fix the scheduler and add more unit tests