attempting to fix race condition a bit better