fixed crashed on exit and on sync