db fixes - 1 bug fix and performance improvement