refactor and tests passing for indexeddb