Implemented flatten