fixed static TLS; code refactoring; bug fixes;