Huge commit after awful lot of hacking