More sql fixes