mass balance function