cleaned up code for calculating grades