Backported Heroku fixes to master branch