Try to clean up KDM creation code a bit.