Based on commit 5ad94253c0c6108a178d84c48ca00d824d9c4c5a by @that1
Depends on commit 86baa648c7f6978e941d8ae18479b0ac94c9ed24 by @that1