use flat_map whenever possible