1.Make API_RESULT_LIMIT and MAXTRHEAD configurable. 2.Add depth. 3.Fix dead-lock.