Issue 504 partial fix.
Merge pull request #562 from iskiselev/Issue504_Partial

Issue 504 partial fix.