refactored updating code