Remove loop from cpu and add to the kernel