implement fixes from #136. Thanks @DasWasser