Bug 1540

Do review:
https://gist.github.com/gruber86/967a2a11b818c9a6e591