Fixed category bugs, added tests.