Moves tasks to threads, code cleanup.
More code cleanup