Database and misc. improvements

Back-end is now able to persist and restore data with [NeDB](https://github.com/louischatriot/nedb) datastores. Other improvements include better logging and assertion, as well as the use of events to reduce coupling between modules.