Updated duration function