add function to calculate material balance