Manually merged @robru's #164 here