Moved messy category code to model