edit gen algorithm