Updated db logic, and addressed notes in code review.