Added waiting before exit