Grammar and other patches from Thomasz