query cleanup