Modified insert and update methods to properly iterate through all dictionary keys