Move get category code to function