Reintroducing time_indexed on upsert, cleaning up code.