Merged in new code from upstream