add the transformmap2kv function and some helper function