Fixes issues #368 and #341

Can be reviewed and merged quickly. @imartinezortiz  may want to take care of this one