solved some thread safe issues