Fix occasional null pointer when accessing the context