Backported fix to #46