refactored db access code out of cli