Refactor name function