main: Change destruction order to fix python stuff