Changed DB flow to work correctly on no-database scenarios.