Database

Refactor all database accesses, fixes #21