Fixed some sql and other errors

Fixed some sql and other script errors