issue_501_sync

this is a continuation for #501 pull request (#611), is now synchronized and mergeable @yegor256 @longtimeago