minor bug fixes and improvement to debug mode