Bugfix
Consistent behavior between windows quit and button
Made code exception safe
Bugfix