Move intermediates into where clause