super inefficient matrix code