Refactored db cursors into a method.