Refactored code due to https://github.com/Gomasy/update_name/issues/4