Improved  to support aliases. Fixes #2240.