more generalized attempt to fix race conditions