Added a check to make sure context exists