Added distance check
Fixed commit merge