Improved memory usage in problem 3 of elem. matrices lab.