Coherent diffractive imaging (CDI) is a lensless imaging technique and can achieve a resolution beyond the Rayleigh or Abbe limit. The ptychographical iterative engine (PIE) is a CDI phase retrieval algorithm that uses multiple diffraction patterns obtained through the scan of a localized illumination on the specimen, which has been demonstrated successfully at optical and X-ray wavelengths. In this paper, a general PIE algorithm (gPIE) is presented and demonstrated with an He-Ne laser light diffraction dataset. This algorithm not only permits the removal of the accurate model of the illumination function in PIE, but also provides improved convergence speed and retrieval quality.