added taskswitching and fixed bugs