refactoring connection and instance