Enhanced UnitFactory with hash function.