Added categorical, reorganized code