Removed dead TLS related code.
More dead code removed related to TLS and threading that is not being used.
Cleaned up a number of warnings due to unused variables, and missing casting.
Final few warnings resolved.