wip: use temp matrices instead of object allocations