Fixing locking of sqldatabases and other small errors