fixed some problems with update function.