Check for d and use kmScalars

Prevents potential divide by zero