code cleanup, map merge and upgrade