added thread stuff - might not be right