Cleaned up multitasking code