Fix for bug #3056

Also added support for host aliases and re-worked duplicate entry handling so it's more robust