using states and calling the update function periodically