refactored for leveldb