implement prev for rdb
refactor readingdb a bit to avoid repeating code