added complete code for building an fptree