some changes for threadsavety