addes saving values for next iteration