Automatically generate categories

Please review.