Fixing SQL flush bug