First if statement is functional and forEach loop is working