fix a bug in head-cycle computation