Some SQL work, minor cleanup