Refactor stacktrace handling.