Modified to handle updates properly