mapper: refactoring & performance improvements