fixed errors that were introduced through flattening