copied toKeyValue from _ extensions