new lines added, a few lines modified to match context (mask operations)
Merge remote-tracking branch 'upstream/master'