Bug fixes for datastore and middleware