Added flatten method.