Added exiting condition