Added modifications to work with Qt5. Added cleanup code