fix the routine mistakes

- rewrite the data loop routine