Fixed a bug in diffperiod optimization