Added loop_flag feature