Refactor the entire thing to be slightly more sane.