Make the app to stop on UI closing

This fixes bug #227.