implemented topN queries. made more informative error messages