Logging now prints to stderr, which is redirected to a log file; cgi handler always responds with json; test API implemented; several bug fixes.