added debounce code to limit switch