Changes merged with upstream.
Duplicated code removed.