database cleanup and fixes