refactor to allow db implementation to be pluggable