fixed some sql syntax related issues