moved kernel generation into a seperate function so it can be reused