Started working on thread. See comments