Added flatten method for WebGL