fix recursion stacktrace by passing db around