Added distance parameter to c function