Fixed some nullPointer crashes on empty/invalid database