Datastore fixes

Helper pull request for @amercader so that he does not have to cherry pick all the commits by himself.