saving samples periodically