More robust database handling when reinstalling

More robust database handling when reinstalling