refactor duplicate code an unused function