Bug fixes, refactoring, improvements. Actual DB access.