Move mapping-iteration logic out of unmap() and into reusable helper.