Improved design
Added database methods
Revert "Improved design"

This reverts commit 416644cc9d5a35731efa84d73b4b4e1be31ed4c6.
Revert "Revert "Improved design""

This reverts commit 7173de71b81124a00548067a0fefb95c153009d6.
Fixed errors