Refactor/cleanup/simplify database access
Some simple validation
Fixes fetching from collections