Refactor reduce for bintree