Changed category calucations

Changed the confusing code to a few lines.