Porting johnronk@1ec7c61 to Pistachitos branch

Closes #448