corrected sync code while shutting down