#4 extended traverse
#5 Added flatten method.