Fixes the "random number of queries" issue sometimes occuring with locmem.