Pulled out generic part of dump_map