refactor grade problem