Working out function tree