when possible, run SQL tests only

Includes some cosmetic/maintainability refactoring.