recactoring context code