fix issues #34 and #35 reported by @chartinger and @tristanbes