Refactoring connection base so it can be used on the client and server side