Revert "Subqueries don't bork so much now, so we can reduce the amount of processing done in python"

This reverts commit bb783b88d5b82423cb2cfa374601091676ab4f41.
Reintroduce small parts of reverted commits that seem to work OK