fixed recursion problem for the event handling