First commit of the rough solution. This is almost certainly FUBAR.