Refactored scheduler and fixed memory manager bug