refactoring code for heroku service