Fixed errors stemming from missing synchronized blocks.

Locking is currently pretty coarse. Once things are working I'll
restructure to minimize the amount of time locks are held.