master and slave work but still some thread safety issues when switching between modes