Code refactoring of method for getting context.