added functinality to sync before closing (not tested yet)