Fix bug in mode change detection