Refactored the name mapping, removed most of the repeating code.