fixed some sql errors