fix the runaway problem and insert test to check