fix db logic