Major refactoring for thread-safety.