refactoring and first connection algorithm implementation with unit
tests