db logic issue - debugging