added local variable to avoid race condition