Giant Refactor

Hi! I don't expect this to get accepted since it is a giant refactor but, in an effort to understand how this was working I broke the tool out of `bin/` into `lib/` and added some minitest.

Feel free to accept or not, just thought I'd share.

Cheers!

Gabe