Improve nested domains handling. For #1451