use a comprehension for one fewer LOC; add ruby-like flatten function