output categories as nested lists, following https://gist.github.com/yellowled/4731544