fixed thread safety bug