Tidied up the update function.