have matrix generation almost working