fix race conditions and correct error sentence