WARNING: The following is done by a trained idiot.