fix sync and query bugs