Added guards for null context