refactor redundant code for cleaning names