Fix several bugs on cycle reference generator