Fix error handling.
Add statistics and exception handling.