working update with better logic