Merge "Exit the loop at the right time" into pi-dev