Move logic of creating connection to a separate class.