Refactoring context connection