Clean code and fix some issues regarding video handle and subwindow management