added code that works with the push button for mode switching