implemented top-level error handling