Adding a function to calculate grade