Moved event target code to a helper function