Refactor the name resolution code.