Backporting return value fixes from master. Fixes Github #19 (reported by kwm81)