Refactoring + fix potential segfault with pyqt 5.3