Move kernel code to KernelThread