Refactor storage modes
Add more utils. Cleanup
Persist db state to db