add update command

and tidy up code