Fix for compilation errors in debug mode.
Fix bug resulted in hard-to-reproduce-and-debug crashes.