fixed sql errors