Improve error handling, expose internal stats

Some very minor fixes.