tried to make this into an each loop but failed