Updated the category lookup function

I think php has some strange behaviour with variables and functions