race condition null pointer bugfix