null check when closing context