Refactor and rewrite of the spaghetti I had in place.