few small sql fixes