Issue/555 categories fix

As of #556.
@batopa: copy-pasted pieces of code edited to match coding standards. Hope everything is fine, now. :wink: