Assorted database structure changes

* put fn/sql/file names in their own separate tables,
* put threaded handler functionality into `StatHandler`
* updated json_api to handle new data format
* various bug fixes along way