fixed lookup-internal (counter comparison), add some debug outputs