modified code to save sim data