Removed superflous loop and used assign instead of capture