added tests
Better thread safety.