Working implementation of cover tree.