Lots of references and bugfixes