Forked from: https://github.com/adtools/flexcat