Why is lists:flatten needed here?