Cleaned up kernel code