Added window closing handler to hide UI, moved visualization complete handler to be called from main thread