fix: additional checks to avoid race conditions