Refactor in-memory database to prepare for real database