added duration calculation function