Refactoring Adx Logic + tests