added test and trying to fix race condition