Eliminate potential NULL dereference.
Fix potential divide by zero. (Highly unlikely, but easy defense.)