Fixed sql errors