fixed matrix stack issue by turning references to matrices into non-pointers