make compatible with heroku and fix bugs