rewrite update code a bit