Adapt changes from @mortik