added serialization for multi-threaded code