Refactoring connection state