fix uninfinite prev and next func bugs