added exit condition