remove duplicate code
Fix minor threading issue (shouldn't ever really matter)