Abstracted as much as I reasonably could for reuse, added general test, added HSQL tests