edited catchematrix.R