fixed db logic