Added thread to do some of the tasks in the background