Fix a bug when reshaping factors inside the integration routines