Add debounce function

Add debounce capability.

Fix partially the 1) of #688