bugfix: memory loss; thread safe;