Refactors repeated process in generate_mappings into _calculate_mappings