Merged from official pull request #630.
Credit by y310.