clean up
Introduce flattenMapIntoAttributes, close #1756