started refactoring update function