minor modification
fixed the looping bug