Bug fixes with scheduler and new tests