move update function outside of main function