race condition fix
potential race condition?
safer way to check for function existence