Add the flatten method and fix a bug in the copy method.