Make listener example more robust