Added Max Distance Logic