AUI-1096 - Improve the logic, add tests