small refactor to avoid multiple event listeners