Refactored more db stuff to use open-run-close