completely revised database handling