Auto-close feature

Now it's crashes at auto-exiting, but it's better than nothing