refactoring code for heroku deployment