Refine algorithm;
Consider more cycle cases.