Working for arbitrary iterations (non-optimized)