Cleaned up the kernel code