refactor map pattern