added empty category check from Amber's code