WIP refactoring exception logic inot query layer