fixed looping bug