fixed a bug about corner cases (sanity check)