Attempt to implement #332 - flattening layers