Fixing unbuffered query exception