Check for NULL connection and context

fixes #155