Refactored code from mapper.