Some changes to the period-finding algorithm; may work better than previous attempt [ci skip]