Refactor into proper module

This enables rake tasks to run natively instead of shelling
out