Modified main stacker query (untested)