Move kernel initialization to a method

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