working sample with exit condition