Fixed #29 implement clean shutdown