Added basic check for undefined category, need to rewrite more eligantly