factoring out a context lookup function