Fix duration calculation and tests