Change some loops to arrays rather than objects