Add header row handling to map; tidy up a bit