refactor and optimize mapper