Since it was not thread safe, add 'synchronized'.