Improve performance: do not update the DOM if not necessary