some absolutely appalling hacking, to be fixed