minor refactoring of kvdb.m code