fix stack depth assertions
remove unbalanced matrix pop ops