I believe that the problem is that the call to
is inside of the refresh function. So if you happen to set the randomButtonId to a value that has already been used it will register another event handler for the same button. This will result in the event handler getting called twice when the button is clicked. If you continue the game it may even get called 3 or more times per button click as you reuse button IDs.
I think the easiest way to fix this is to move the onEvent call outside of the refresh function and register the handler for all four buttons. Then simply save and check the correct button ID in a global variable when the event executed.
Does that make sense?