Adding a upsert function

Create element, check if it already exists and update it if so.