Support added to relay domain aliases.

I've also refactored some code.
see #491