inproved kernel state-machine