Refactored the 2 for loops to use Array filter and forEach