Fixed insert / upsert and added a simple test case.