Factored out a function to update the DOM