Improve error reporting; add basic performance tracing