use collectFirst instand of a var and iterate