Put synchronized block around possible race condition