refactored the shit out of this thing, basically working, still a few bugs and lots of tests to write, addresses #17