Codes for fanfan's work