Merged in some changes from upstream