reorganized kernel code