Fix debounce bug and improve wait time calcuation

not tested, have fun;)