Refactor in kernel.c and class.c