Rewrite update_output as function