bug fixes for sql