refactored scheduler