map maintains order, and some cleanup
merged