Working version. Slow, but completes the job fairly well. Not super robust yet, could use much tweaking. Adding useful features and optimizing next.