Refactor into gem
Get gem working right