few fixes here and there, check the diff

- some of the sql queries had invalid syntax
- also, for the Category map, you cannot use any index, it has to match the "old category id", aka `_cid`