Bug 1511

Do review
https://gist.github.com/gruber86/7dcada430fb83ca6dbb2