added exit check