fixed SQL errors