Changed from synchronized methods to synchronized blocks.