Added bug fixes to SQL context