Refactoring and reorganisation of the scheduler