Changed locks to synchronizing and other cleanup.