Enhance scheduler mechanism and clean test code.