Added flatten/unflatten to utils