refactor out subquery condition check, added test for subquery specific functions