Ensure thread safety