few sql fixes