revised exit logic