Generalized the return type of diffract_gather. Fixed a bug in prime application