Put mapping logic into a function