grade calc code