Issue#596

Fixing issue #596 
Also #595 should be merged at the same time with this one.