Author: Lars Francke <lars.francke@gmail.com> (cherry picked from commit cb8d679c95642842efacc5d38ccf2a61b043c689)