refactoring and putting IDs into array to map through