reworked connection algo for using distances vs modulo, some other minor changes