fixed bug of judging starting from after index 0