refactored update logic