fixed bugs in clustering algorithm and in queries