Added error-checking for invalid grades.