Fixed some sql errors