add loop indcator and fix some sanity check