Refactoring

Closes #30 
Various edits and enhancements related to SQL statements.
Some effort toward #12 - Added more dynamic handling of endpoints.