Rebased to lanyon uppstream, this commit contains typfixes