some sql fixes