This is based on the approach of sasajuric: https://gist.github.com/sasa1977/bf9a50d2caeb2534c4e557d37ca5e08a