Refactor the names parsing code.