Rough implementation of scheduler and dispatcher