added nil check on newdatabase