modified to store into mat files