wrote working code that stores intermediate query results