improve error reporting, add profiling