implemented generation with restarts