Implemented collapse argument
implemented max.n argument