Fixing sql errors