HIVE-7068 Lift more inner classes into their own file. Restructure some methods to make them more testable