Implemented super fast topN query

Also made some more informative error messages.