Convert more data methods to use sqlalchemy, and fix some issues found along the way.