ptypes 2.1.1 from Hovik Melikyan plus some changes of mine