manual merge of Aki Tuomi's pull request #1263. Thanks!