Refactors history and how the database is stored
Merge pull request #4559 from yurydelendik/history

Refactors history and how the database is stored