Fix for rev.221167
Fix for rev.221375
Merge pull request #898 from Vsevolod-Livinskij/fix_for_trunk

Fix for trunk (rev. 221167 and rev. 221375)