fixing sql errors