Fixed a bug with scheduler