An improved ptychographical phase retrieval algorithm for diffractive imaging