race conditions and whatnot fixed