grade logic