lots of debug code for knowledge sharing.

misc bug fixes in handle percepts