Cleaned up code for integration with rest of r-tree.