Added logic to calculate grade