Improved 'check_result' function.