[#519] Move duplicated code to a common place MapUtils