Repair the structure to what @Folis uses.
Optimize imports, fix PyCharm warnings.