Updated flatten to work with n-nested iterables.