prevent too many dom updates that slow the browser down
fixed logic bug
fixed typo in js