Fix some warnings, add debug checks