Include subquery refactor

*WORK IN PROGRESS*

This is work to improve the subquery logic to counter double joins etc.