refactoring & work on map connection algorithm