refactor map ops code