Solving memory leak problems and updating dataset.token to accept matrices as tokens in putPattern methods