Make the self-updating function a bit more robust