Fix calculation of preferred and valid times