Fixed bug in updating function.