Refactor database

Various improvements. Merged main database with tags.