Work in progress, adding changes as per Jonas's advice