Refactor map iteration