Tweaks to sub query