refactored tileConnection algorithm