Added a fix to create the directories and matrix file if they don't already exist