Rewrote query based on advice - hasn't been tested yet