completely rewritten kernel scanning macro