Revised the termination handling
Fix a potential issue which might cause QuadUI freeze during running