Make scheduler parametric

Also some minor refactoring