changed replace to upsert
changed to use switch