Cleanup code to remove dbg compile warnings

Closes #4006.