Refactor kernel.c and class.c