bug in the udpate function fixed