Fixed some bugs with category querying. Added tests file.