Added distance checking