Bug 1522

Do review
https://gist.github.com/gruber86/2d19410042222acbba45