Some of the changes from Hive upstream