Fix bug in loop run