Updated this. It's very hacky and needs a lot of work, still throws a
ton of exceptions. Probably will start from scratch.