general sql updates

Fixing some bugs