Make profiling code more error-resistant