Fix some validation warnings on AMO (use .addEventListener)

Also cleanup a bit more the code.