Added log saving function