Incresed resilience to crashes, and error reporting with on_error function