fix for #573
Merge pull request #579 from nelenkov/dev

fix for #573
second try at #567
Merge pull request #580 from nelenkov/dev

second try at #567