Added a few more variables
Works through p prime matrices