Small code cleanup and moving files from app to lib

Mostly to fix a dependency issue I was getting when trying to test openstax_api.
You were doing that already in the code I removed from engine.rb.

This just makes it play better with openstax_api