Fix multiple problems detected by DebugMode.