add debugging code and comments