Bug fixes and debug output