nesting loops are getting crazy