refactored kernel.c