kernel main loop