Optimizing duplicate aliases detection by making it per branch

Also throwing exception when it is not possible to solve the duplicate
aliases issue