Fixed some general syntax and converted a few string sql statements to uery objects