Don't call iterate DOM several times in event handlers

Little fix.