Add #3463 commits from @ghost

Initial commit from changes made by @ghost
Comment above would be nicer as it's hard to read like this