Refactor update logic