Why is the udpate loop not correct?