fixes some sql