Use mapcat instead of flatten