Implementing upsert functionality.