Make some call of unlist() and matrix() more efficient