Factor out the code to update the GUI, so it can be re-used