Fixed debounce code, which would only have worked properly once out of every 248 times.