Added thread stuff that is almost working