added methods for implementing flatten, but need to still finish.