use atom instead of mutating var in collect