Merge of #361 to master

I squashed the commits for master: it's cleaner this way.