Adding graceful exit condition.