Refactoring, better thread safety, better API type safety