sql updates and bugfixes