debugged matrix import function