Added distance calculation code.