Change some each loops to use collect instead