Handle aliases correctly

Per comment from Peter Geoghegan.