Refactoring the code for grade overriding and tests.

TNL-900