terms function adds to proper array