Fixed some SQL errors