Make stop command more robust, and use it in test