little fixes to database thread