use map instead of each

now the correct array is being returned
factor out two more methods