Parts of https://github.com/PRX/apn_on_rails/pull/47