pure functional btree implementation