Fixed read and write of KDTree