Starts of refactoring logic out of app.rb and into a library