Added flatten methods, and added toList and toArray as well.