moved nested where clauses to the subquery if needed. closes #252