refine context function