HIVE-7659: refine the code