wrap with function inside loops

if not, `dest` would always be the last one.