rewrite using map as core.