Move kernel initialization to a method

I just changer the kernel initialization to a method to improve readability.